package com.efast.dmom.mgmt.service.les.impl;

import com.efast.dmom.mgmt.bean.les.PdaResultTwOutbTaskDetailBean;
import com.efast.dmom.mgmt.dao.les.TwOutbTaskDetailDao;
import com.efast.dmom.mgmt.dao.les.TwOutbTaskHeaderDao;
import com.efast.dmom.mgmt.entity.les.TwOutbTaskDetail;
import com.efast.dmom.mgmt.entity.les.TwOutbTaskHeader;
import com.efast.dmom.mgmt.service.les.TwOutbTaskDetailService;
import com.efast.dmom.mgmt.utils.Assist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chlp
 */
@Service
public class TwOutbTaskDetailServiceImpl implements TwOutbTaskDetailService {

	private final TwOutbTaskDetailDao twOutbTaskDetailDao;
	private final TwOutbTaskHeaderDao twOutbTaskHeaderDao;

	@Autowired
	public TwOutbTaskDetailServiceImpl(TwOutbTaskDetailDao twOutbTaskDetailDao,
			TwOutbTaskHeaderDao twOutbTaskHeaderDao) {
		this.twOutbTaskDetailDao = twOutbTaskDetailDao;
		this.twOutbTaskHeaderDao = twOutbTaskHeaderDao;
	}

	@Override
	public int updateNonEmptyTwOutbTaskDetailById(TwOutbTaskDetail enti) {
		TwOutbTaskDetail twOutbTaskDetail = new TwOutbTaskDetail();
		twOutbTaskDetail.setTwOutbTaskDetailId(enti.getTwOutbTaskDetailId());
		// 拣货状态（新任务0，任务完成1，2部分拣货）
		twOutbTaskDetail.setPickStatus("0");
		TwOutbTaskDetail twOutbTaskDetail1 = twOutbTaskDetailDao.selectTwOutbTaskDetailById(
				enti.getTwOutbTaskDetailId());
		TwOutbTaskHeader twOutbTaskHeader = new TwOutbTaskHeader();
		twOutbTaskHeader.setTwOutbTaskHeaderId(twOutbTaskDetail1.getTwOutbTaskHeaderId());
		// 拣货状态: 0新任务 1拣货完成 2部分拣货 3关闭
		twOutbTaskHeader.setInboundStatus("2");
		// 单行变成新单，整单变成部分拣货
		twOutbTaskHeaderDao.updateNonEmptyTwOutbTaskHeaderById(twOutbTaskHeader);
		return twOutbTaskDetailDao.updateNonEmptyTwOutbTaskDetailById(twOutbTaskDetail1);
	}

	/**
	 *
	 * 根据拣货任务头表id，查询明细数据
	 *
	 * @param twOutbTaskHeaderId
	 *            twOutbTaskHeaderId
	 * @return List<PdaResultTwOutbTaskDetailBean>
	 */
	@Override
	public List<PdaResultTwOutbTaskDetailBean> queryTaskDetailService(Integer twOutbTaskHeaderId) {
		return twOutbTaskDetailDao.queryTaskDetailService(twOutbTaskHeaderId);
	}

	@Override
	public long getTwOutbTaskDetailRowCount(Assist assist) {
		return twOutbTaskDetailDao.getTwOutbTaskDetailRowCount(assist);
	}

	@Override
	public List<TwOutbTaskDetail> selectTwOutbTaskDetail(Assist assist) {
		return twOutbTaskDetailDao.selectTwOutbTaskDetail(assist);
	}

	@Override
	public TwOutbTaskDetail selectTwOutbTaskDetailByObj(TwOutbTaskDetail obj) {
		return twOutbTaskDetailDao.selectTwOutbTaskDetailByObj(obj);
	}

	@Override
	public TwOutbTaskDetail selectTwOutbTaskDetailById(Integer id) {
		return twOutbTaskDetailDao.selectTwOutbTaskDetailById(id);
	}

	@Override
	public int insertTwOutbTaskDetail(TwOutbTaskDetail value) {
		return twOutbTaskDetailDao.insertTwOutbTaskDetail(value);
	}

	@Override
	public int insertNonEmptyTwOutbTaskDetail(TwOutbTaskDetail value) {
		return twOutbTaskDetailDao.insertNonEmptyTwOutbTaskDetail(value);
	}

	@Override
	public int insertTwOutbTaskDetailByBatch(List<TwOutbTaskDetail> value) {
		return twOutbTaskDetailDao.insertTwOutbTaskDetailByBatch(value);
	}

	@Override
	public int deleteTwOutbTaskDetailById(Integer id) {
		return twOutbTaskDetailDao.deleteTwOutbTaskDetailById(id);
	}

	@Override
	public int deleteTwOutbTaskDetail(Assist assist) {
		return twOutbTaskDetailDao.deleteTwOutbTaskDetail(assist);
	}

	@Override
	public int updateTwOutbTaskDetailById(TwOutbTaskDetail enti) {
		return twOutbTaskDetailDao.updateTwOutbTaskDetailById(enti);
	}

	@Override
	public int updateTwOutbTaskDetail(TwOutbTaskDetail value, Assist assist) {
		return twOutbTaskDetailDao.updateTwOutbTaskDetail(value, assist);
	}

	@Override
	public int updateNonEmptyTwOutbTaskDetail(TwOutbTaskDetail value, Assist assist) {
		return twOutbTaskDetailDao.updateNonEmptyTwOutbTaskDetail(value, assist);
	}

}